package com.liu.qa.dao;

import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.liu.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{

    /**
     * 查询最新问题答复列表，分页
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value = "SELECT * from tb_problem ,tb_pl where problemid =id and labelid= ? ORDER  BY replytime DESC ",nativeQuery = true)
    public Page<Problem> findByNewListByLabelId(String labelId, Pageable pageable);

    /**
     * 查询热门的回答列表
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value="SELECT * from tb_problem ,tb_pl where problemid =id and labelid= ? ORDER  BY reply DESC",nativeQuery = true)
    public Page<Problem> findHotListByLableId(String labelId,Pageable pageable);

    /**
     * 查询待回答列表
     * @param labelId
     * @param pageable
     * @return
     */
    @Query(value="SELECT * from tb_problem ,tb_pl where problemid =id and labelid= ? and reply =0 ORDER  BY createtime DESC",nativeQuery = true)
    public Page<Problem> findWaitListByLableId(String labelId,Pageable pageable);


}
